Title: Exercise 1:
Author: William Emigh
Last saved by: salewis

EPICS Lab Part 4: Database to Communicate with a PLC	
In this exercise you will add support for an Allen-Bradley PLCs to your IOC.  First you need to do some initial setup to add the ether-ip driver to your IOC, then you just need to add new records to your database.
Set up your IOC to communicate with a PLC
Use a text editor to add the following line to ioctop/configure/RELEASE, immediately above the line beginning with EPICS_BASE=
	# Ether-IP Driver:
	ETHER_IP=/nfs/slac/g/lcls/build/epics/modules/ether_ip/ether_ip-R2-5-lcls1
Use a text editor to add the following lines to ioctop/appnameApp/src/Makefile, immediately below the line beginning with appname_DBD += appnameHello.dbd:
	# EtherIP
	appname_DBD += ether_ip.dbd
	appname_DBD += drvEtherIP.dbd
Use a text editor to add the following lines to ioctop/appnameApp/src/Makefile, immediately below the line beginning with appname_LIBS += xxxSupport:
	# ether-ip
	appname_LIBS += ether_ip
Use a text editor to add the following lines to ioctop/iocBoot/iocappname/st.cmd, immediately below the last dbLoadRecords line :
	## Initialize EtherIP driver and define PLC
	drvEtherIP_init()
	## drvEtherIP_define_PLC <name>, <ip_addr>, <slot>
	drvEtherIP_define_PLC("plc1", "plcipaddress", slot#)
	EIP_verbosity(8)
	drvEtherIP_default_rate(5)
Replace plcipaddress with the ip address (###.###.###.###) of your PLC. 
Replace slot# with the slot in the PLC crate where the controller module is installed (probably 0)

Build your IOC (see instructions on IOC Development Workflow sheet)

Add PLC records to your database
Run vdct:
$ cd ioctop
$ vdct dbd/appname.dbd
Open the database ioctop/appnameApp/Db/dbExample1.db.  Warning: DO NOT open the file ioctop/db/dbExample1.db.  If you accidentally open this file instead of the one in 
appnameApp/Db, all your changes will be lost when you build your IOC!
In the dbExample1 database, add the following records:
•	A binary input record that gets its data from an element of a DINT array on the PLC.  
The DTYP should be etherip
The INP field should be @plc1 arrayname B element
The ZNAM and ONAM fields should have names that reflect the 0 and 1 states of the tag.
The SCAN field should be set to the desired update rate from the PLC.
•	A binary output record that writes to an element of a DINT array on the PLC.  
The DTYP should be etherip
The OUT field should be @plc1 arrayname B element
The ZNAM and ONAM fields should have names that reflect the 0 and 1 states of the tag.
The SCAN field should be Passive.
•	An analog input record that gets its data from an element of a REAL array on the PLC.  
The DTYP should be etherip
The INP field should be @plc1 arrayname[element]
The SCAN field should be set to the desired update rate from the PLC.
•	An analog output record that writes to an element of a REAL array on the PLC.  
The DTYP should be etherip
The OUT field should be @plc1 arrayname[element]
The SCAN field should be Passive.
•	Additional soft records (calc records, etc) to do interesting things with the PLC data.
•	All the records should have unique names incorporating the macro $(user)which will expand to it when the database is loaded.  Save the database.
•	Make sure that all of the records will process.
Rebuild the IOC (see IOC Development Workflow sheet)
Boot the IOC (see IOC Development Workflow sheet)
Test the database:
•	Use edm to create a display that shows the values of your new records.
•	Create text update objects that connect to the VAL fields of all your input records.
•	Create text entry objects that connect to the VAL fields of all your output records.
•	Using your new objects, try to change the value of the output records.  See if the PLC tags change when you do this.  Change values of tags on the PLC and see if your input records change.

EPICS_Lab_Part4_Database_PLC		page  of